var flag = false;
var confirm = false;
function showPopup() {
    if ($(".cqchoosenum").hasClass("pop_payss")) {
        $(".cqchoosenum").removeClass("pop_payss");
        $("#background").hide();
    } else {
        $(".cqchoosenum").addClass("pop_payss");
        $("#background").show();
    }
}

function pay_indent(typeid) {
    var requrl = location.href.split('#')[0];
    $(".cqchoosenum").removeClass("pop_payss");
    $("#background").hide();
    if (flag)
        return;
    flag = true;
    var token = $("#token").val();
    if (isempty(token)) {
        location.href = "/except/login.jsp";
        return;
    }
    var paytype = 1;
    $("#paytype :radio").each(function () {
        var checked = $(this).attr("checked");
        if (checked)
            paytype = $(this).val();
    });
    var indentnum = $("#indentnum").val();
    var jsonstr = "{token:" + token + "}";
    var url = "/except/indentcontroller/repertorypay.action";
    $.ajax({
        url: url,
        type: 'post',
        dataType: "json",
        data: {
            json: jsonstr,
            typeid: typeid,
            paytype: paytype,
            requrl:requrl
        },
        async: false,
        success: function (data) {
            var code = data.code;
            var message = data.message;
            if (code == 10001 || code == 10002)
                location.href = "/except/login.jsp";
            else if (code == 20000) {
                $("#hint_message").html("支付成功");
                $("#hintbg").show();
                location.href = "/except/files/indent/repertory.jsp";
                confirm = true;
            } else {
                $("#hint_message").html(message);
                $("#hintbg").show();
                flag = false;
            }
        }
    });
}

$(function () {
    remove_advertising();
    $("#confirm_btn").click(function () {
        if (confirm)
            location.href = "/except/paysuccess.jsp?indenttype=2";
    });
});